package corp.sunny.sso.dao;

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;

import corp.sunny.commons.util.spring.SpringUtil;
import corp.sunny.frameworks.dao.AbstractBaseDAO;
import corp.sunny.frameworks.exception.DAOException;
import corp.sunny.sso.domain.SSOUserAcct;

/**
 * @File:AuthenticationServiceDAO.java
 * @Date:Jun 15, 2011
 * @Author:Subhash Bavi
 * 
 * @Description:
 * @Copyright Sunny Corporation - 2011
 */
public class AuthenticationServiceDAO extends AbstractBaseDAO {

	final Logger LOG = Logger.getLogger(AuthenticationServiceDAO.class);
	List<SSOUserAcct> list;

	HibernateTemplate hibernateTemplate = (HibernateTemplate) SpringUtil
			.getBean("hibernateTemplate");
	SSOUserAcct ssoUserAcct = (SSOUserAcct) SpringUtil.getBean("ssoUserAcct");
	SSOUserAcct iAccount = (SSOUserAcct) SpringUtil.getBean("ssoUserAcct");
	SessionFactory sessionFactory = (SessionFactory) SpringUtil
			.getBean("sessionFactory");

	@SuppressWarnings("unchecked")
	@Override
	/**
	 * Fetches the UserAcct
	 */
	public Object find(Object obj) throws DAOException {

		if (null == obj) {
			throw new DAOException("AUTHSERVICE_DAO_OBJ_NULL",
					"object passed to DAO cannot be null");
		}

		ssoUserAcct = (SSOUserAcct) obj;
		list = hibernateTemplate
				.find("from SSOUserAcct usrAcct where usrAcct.user='"
						+ ssoUserAcct.getUser() + "'");
		iAccount = list.get(0);
		LOG.info("iAccount :: " + iAccount);
		return iAccount;
	}

	@Override
	protected HibernateTemplate getHibernateTemplate() {
		// TODO Auto-generated method stub
		return null;
	}
}